﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace SynchronizationStudy
{
    class SemaphoreTest
    {
        public static void Test()
        {
            var sh = new Semaphore(0, 2);

            Task.Run(() =>
            {
                sh.WaitOne();
                Thread.Sleep(200);
                Console.WriteLine("A");
                sh.Release();
            });

            Task.Run(() =>
            {
                sh.WaitOne();
                Thread.Sleep(100);
                Console.WriteLine("B");
                sh.Release();
            });

            sh.Release(2);

            Console.ReadLine();
        }
    }
}
